﻿using System;
using System.Data;
using System.Collections.Generic;
using OgilvyOne.Model;
using OgilvyOne.DALFactory;
using OgilvyOne.IDAL;
using OgilvyOne.DALFactory.cofco.product;
namespace OgilvyOne.BLL
{
    /// <summary>
    /// ProductInfoBll
    /// </summary>
    public partial class ProductInfoBll
    {
        private readonly IProductInfo dal = ProductInfoFactory.create();
        public ProductInfoBll()
        { }
        #region  Method
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string name, int PRODUCT_ID)
        {
            return dal.Exists(name, PRODUCT_ID);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(ProductInfoModel model,string typeIdlist)
        {
            return dal.Add(model,typeIdlist);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(ProductInfoModel model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int PRODUCT_ID)
        {

            return dal.Delete(PRODUCT_ID);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string PRODUCT_IDlist)
        {
            return dal.DeleteList(PRODUCT_IDlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ProductInfoModel GetModel(int PRODUCT_ID)
        {

            return dal.GetModel(PRODUCT_ID);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ProductInfoModel GetModelByOrderNum(int orderNum,int id)
        {

            return dal.GetModelByOrderNum(orderNum,id);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<ProductInfoModel> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<ProductInfoModel> DataTableToList(DataTable dt)
        {
            List<ProductInfoModel> modelList = new List<ProductInfoModel>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                ProductInfoModel model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new ProductInfoModel();
                    if (dt.Rows[n]["PRODUCT_ID"].ToString() != "")
                    {
                        model.Productid = int.Parse(dt.Rows[n]["PRODUCT_ID"].ToString());
                    }
                    model.Productname = dt.Rows[n]["PRODUCT_NAME"].ToString();
                    if (dt.Rows[n]["PRODUCT_TYPE_ID"].ToString() != "")
                    {
                        model.Producttypeid = int.Parse(dt.Rows[n]["PRODUCT_TYPE_ID"].ToString());
                    }
                    if (dt.Rows[n]["PRODUCT_BRAND_ID"].ToString() != "")
                    {
                        model.Productbrandid = int.Parse(dt.Rows[n]["PRODUCT_BRAND_ID"].ToString());
                    }
                    model.Productdesc = dt.Rows[n]["PRODUCT_DESC"].ToString();
                    model.Productimg = dt.Rows[n]["PRODUCT_IMG"].ToString();
                    if (dt.Rows[n]["ORDER_NUM"].ToString() != "")
                    {
                        model.Ordernum = int.Parse(dt.Rows[n]["ORDER_NUM"].ToString());
                    }
                    model.Buylink = dt.Rows[n]["BUY_LINK"].ToString();
                    if (dt.Rows[n]["STATE"].ToString() != "")
                    {
                        model.State = int.Parse(dt.Rows[n]["STATE"].ToString());
                    }
                    if (dt.Rows[n]["ADD_TIME"].ToString() != "")
                    {
                        model.Addtime = DateTime.Parse(dt.Rows[n]["ADD_TIME"].ToString());
                    }
                    model.Addusername = dt.Rows[n]["ADD_USERNAME"].ToString();
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  Method
    }
}

